package com.jbm.jbmsupplier.net.busheven;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by 家帮忙 on 2016/11/28.
 */

public class UtlisNetWork {

    //没有网络链接
    private static  final int NETWORK_NONE=-1;
    //移动网络
    private  static  final  int NETWORK_OBILE=0;
    //无线网络
    private  static  final int NETWORK_WIFI=1;
    public static  int getnetwokstate(Context context){
        ConnectivityManager connectvity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo getnewworkinfo = connectvity.getActiveNetworkInfo();
        if (getnewworkinfo!=null&&getnewworkinfo.isAvailable()){//getnewworkinfo.isAvailable()&&
            if (getnewworkinfo.getType()==(connectvity.TYPE_WIFI)){
                return NETWORK_WIFI;
            }else if(getnewworkinfo.getType()==(connectvity.TYPE_MOBILE)){
                return NETWORK_OBILE;
            }
        }else{
            return NETWORK_NONE;
        }
        return  NETWORK_NONE;
    }

}
